package com.atguigu.gulimall.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author kabuda
 * @create 2022-12-03 15:10
 */
@Data
public class Cart {
    private List<CartItem> items;
    private Integer countNum; //购物车项总数量
    private Integer countType; //购物车项类型数量
    private BigDecimal totalAmount; //购物车总价
    private BigDecimal reduce=BigDecimal.ZERO; //优惠减免

    public Integer getCountNum() {
        countNum=0;
        if(items!=null&&items.size()>0){
            for (CartItem item : items) {
                countNum+=item.getCount();
            }
        }
        return countNum;
    }

    public Integer getCountType() {
        countType=0;
        if(items!=null&&items.size()>0){
            for (CartItem item : items) {
                countType+=1;
            }
        }
        return countType;
    }

    public BigDecimal getTotalAmount() {
        totalAmount=BigDecimal.ZERO;
        if(items!=null&&items.size()>0){
            for (CartItem item : items) {
                if(item.getCheck()){
                    totalAmount=totalAmount.add(item.getTotalPrice());
                }
            }
            totalAmount= totalAmount.subtract(reduce);
        }
        return totalAmount;
    }



}
